package com.wl.spring.mvc.web;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyReqHandler implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //请求到达目标资源呢之前,执行的代码
        System.out.println("------------------请求到达目标资源呢之前,执行的代码----------------");
        //允许访问目标资源，返回true
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        //请求从目标资源返回，执行代码
        System.out.println("------------------请求从目标资源返回，执行代码----------------");
        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
    }


    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("------------------从页面返回，执行代码----------------");
        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
    }

}
